﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace BDH.PRE
{
  //  using BDH.DAL;
    public partial class FrmMain : RibbonForm
    {
        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static UTL.Session _sss = new UTL.Session();
        public static bool _setDB = false;
        public static string _User;

        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();
        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            try
            {
                //bsiServer.Caption = String.Format("[SERVER:{0} | DB:{1}]",
                //                         DAL.BaseDAL.CurrentConnectInfo.Server,
                //                         DAL.BaseDAL.CurrentConnectInfo.Database);
                //var sql = new DAL.SQLServer();
                //if (!sql.CheckDbExists(BDH.DAL.SQLServer.DbName))
                //    btnCaidat_ItemClick(sender, null);
                //else
//#if RELEASE
                    btnDangnhap_ItemClick(sender, null);
//#endif
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,ex.ToString());
            }
        }

        private void btnNhatro_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Form.FrmNhatro) return;
            var frm = new Form.FrmNhatro() { MdiParent = this };

            frm.Show();
        }

        private void btnQuan_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Form.FrmQuan) return;
            var frm = new Form.FrmQuan() { MdiParent = this };

            frm.Show();
        }

        private void btnPhuong_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Form.FrmPhuong) return;
            var frm = new Form.FrmPhuong() { MdiParent = this };

            frm.Show();
        }

        private void btnDuong_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Form.FrmDuong) return;
            var frm = new Form.FrmDuong() { MdiParent = this };

            frm.Show();
        }

        private void btnCaidat_ItemClick(object sender, ItemClickEventArgs e)
        {
            var frm = new FrmSetting();
            frm.ShowDialog();
        }

        private void btnDangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (btnDangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                btnDangnhap.Caption = STR_LOGIN;

                barButtonItem1_ItemClick(sender, e);
            }

            FrmLogin x = new FrmLogin();
            x.ShowDialog();

            if (_sss.Login)
            {
                bsiUser.Caption = _sss.Name;
                _User = _sss.Acc;
                btnDangnhap.Caption = STR_LOGOUT;
                rpNhatro.Visible = true;
            }
            else
            {
                rpNhatro.Visible = false;
            }

            //EnableMenu();
        }

        private void iExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
        }

      

      


       
    }
}